var mysql_credential = require('../credentials');
var mysql = require('mysql');
var db = {};
var connection = mysql.createConnection(mysql_credential.mysql);


connection.connect(function (err) {
    if(err){
        console.log(err);
        return;
    }
});
db.query = function sqlback(sqlan,fn) {


    var sql = sqlan;
    if(!sql) return;
    connection.query(sql, function (err, rows, fields) {
        if(err){
            console.log(err);
            return;
        }
        fn(rows);
    })

};
db.insert = function insertBack(sql1,sql2, fn) {
    let sql = sql1;
    if(!sql) return;
    connection.query(sql1, sql2, function (err, rows) {
        if(err) {
            console.log(err);
            return
        }
        fn(rows)
    })
}
module.exports = db;